<?php
// +----------------------------------------------------------------------
// | 登录验证中间件
// +----------------------------------------------------------------------
namespace app\admin\middleware;

use app\common\service\SysMenuService;
use app\common\service\SysRoleService;
use think\facade\Log;

class Auth
{
    public function handle($request, \Closure $next)
    {   
        try{
            $userInfo = session("userInfo");
            if (empty($userInfo)) {
               return redirect((string) url("PublicController/login"));
            }
            // $current = $request->controller().'/'.$request->action();
            // $perms = array_column(flattenMenuArray(session('menuList')), 'perms');
            // if (!in_array($current, $perms) && $current != "Dashboard/index") {
            //     return failure(500, "没有权限");
            // }

        }catch (\Exception $e) {
            Log::error("Auth is error," . $e->getMessage());
            return redirect((string) url("PublicController/login"));
        }

        return $next($request);
    }


}